---@class components
---@field surtr_laevatain_fn component_surtr_laevatain_fn

local function on_goldenaxe(self, value)
    self.inst.replica.surtr_laevatain_fn:Setgoldenaxe(value)
end

local function on_goldenpickaxe(self, value)
    self.inst.replica.surtr_laevatain_fn:Setgoldenpickaxe(value)
end

local function on_ash(self, value)
    self.inst.replica.surtr_laevatain_fn:Setash(value)
end

---@class component_surtr_laevatain_fn
---@field inst ent
---@field goldenaxe boolean
---@field goldenpickaxe boolean
---@field ash number
local surtr_laevatain_fn = Class(function(self, inst)
    self.inst = inst
    -- self.val = 0
    self.goldenaxe = false
    self.goldenpickaxe = false
    self.ash = 0
end,
nil,
{
    -- val = on_val,
    goldenaxe = on_goldenaxe,
    goldenpickaxe = on_goldenpickaxe,
    ash = on_ash,
})

function surtr_laevatain_fn:OnSave()
    return {
        goldenaxe = self.goldenaxe,
        goldenpickaxe = self.goldenpickaxe,
        ash = self.ash,
    }
end

function surtr_laevatain_fn:OnLoad(data)
    self.goldenaxe = data.goldenpickaxe
    self.goldenpickaxe = data.goldenpickaxe
    self.ash = data.ash

    if self.goldenpickaxe then
        self.inst:AddTag(ACTIONS.MINE.id.."_tool")
    end
    if self.goldenaxe then
        self.inst:AddTag(ACTIONS.CHOP.id.."_tool")
    end
    if self.ash and type(self.ash) == 'number' and self.ash > 0 then
        if self.inst.components.planardamage then
            self.inst.components.planardamage:SetBaseDamage(self.ash * TUNING.MOD_SURTR.LAEVATAIN.ACCEPT.surtr_ash.planardmg_per)
        end
    end
end

function surtr_laevatain_fn:AddAsh()
    self.ash = self.ash + 1
    if self.inst.components.planardamage then
        self.inst.components.planardamage:SetBaseDamage(self.ash * TUNING.MOD_SURTR.LAEVATAIN.ACCEPT.surtr_ash.planardmg_per)
    end
end

function surtr_laevatain_fn:AddGoldenAxe()
    self.goldenaxe = true
    self.inst:AddTag(ACTIONS.CHOP.id.."_tool")
end

function surtr_laevatain_fn:AddGoldenPickAxe()
    self.goldenpickaxe = true
    self.inst:AddTag(ACTIONS.MINE.id.."_tool")
end

return surtr_laevatain_fn